package com.demo.spring.formework.aop.aspect;

import com.demo.spring.formework.aop.QBMethodInvocation;

import java.lang.reflect.Method;

public class QBAroundAdvice extends QBAbstractAspectJAdvice implements QBAdvise,QBMethodInterceptor {

    private QBJoinPoint joinPoint;

    public QBAroundAdvice(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }

    public Object invoke(QBMethodInvocation mi) throws Throwable {
        joinPoint = mi;

        before();
        Object retVal = mi.proceed();
        after(retVal);

        return retVal;
    }

    public void before() throws Throwable {
        invokeAdviceMethod(joinPoint,null,null);
    }

    public void after(Object retVal) throws Throwable {
        invokeAdviceMethod(joinPoint,retVal,null);
    }
}
